package com.cgt.web.service.impl;

import com.cgt.web.dao.IClassDao;
import com.cgt.web.dao.impl.ClassDaoImpl;
import com.cgt.web.pojo.Classroom;
import com.cgt.web.service.IClassService;
import com.cgt.web.util.PageInfo;

import java.util.List;

public class ClassServiceImpl implements IClassService {
    private IClassDao classDao = new ClassDaoImpl();
    @Override
    public PageInfo<Classroom> selectByPage(int pageNo, int pageSize) {
        int offset = (pageNo - 1) * pageSize;
        List<Classroom> list = classDao.selectByPage(offset,pageSize);
        int totalcount = classDao.selectTotalCount();
        int totalPage = (int) Math.ceil((double) totalcount / pageSize);
        PageInfo pageInfo = new PageInfo(list,pageNo,pageSize,totalPage);
        return pageInfo;
    }

    @Override
    public void deleteById(int id) {
        System.out.println("ClassServiceImpl.deleteById");
        classDao.deleteById(id);
    }

    @Override
    public void addInf(Classroom classroom) {
        System.out.println("ClassServiceImpl.addInf");
        classDao.addInf(classroom);
    }

    @Override
    public Classroom selectById(int id) {
        System.out.println("ClassServiceImpl.selectById");
        return classDao.selectById(id);
    }

    @Override
    public void updateInf(Classroom classroom) {
        System.out.println("ClassServiceImpl.updateInf");
        classDao.updateInf(classroom);
    }
}
